package com.geekchique.runningbuddy.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.Menu.Item;
import android.widget.ImageButton;

import com.geekchique.runningbuddy.R;
import com.geekchique.runningbuddy.controller.HomeControllerImpl;
import com.geekchique.runningbuddy.controller.IHomeController;
import com.geekchique.runningbuddy.controller.IOptionsMenu;
import com.geekchique.runningbuddy.controller.OptionsMenuImpl;
import com.geekchique.runningbuddy.service.RemoteStopClockServiceInterface;

public class Home extends Activity {

	private IHomeController homeController;
	private IOptionsMenu optionsMenu;

	@Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);
        setContentView(R.layout.home);
		optionsMenu = new OptionsMenuImpl(this);

        homeController = new HomeControllerImpl(this);

        homeController.createHomeView(
        		this,
        		(ImageButton)findViewById(R.id.goto_stopwatch),
        		(ImageButton)findViewById(R.id.goto_today)
        );

    }

    @Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		optionsMenu.addAllActivitiesToMenu(menu);
		return true;
	}

	@Override
	public boolean onOptionsItemSelected(Item item) {
		optionsMenu.selectItem(item);
	    return super.onOptionsItemSelected(item);
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		return homeController.onKeyDown(keyCode, event);
	}

	@Override
	protected void onStop() {
		super.onStop();
		RemoteStopClockServiceInterface.getInstance().activityStopped(this);
	}

	@Override
	protected void onStart() {
		super.onStart();
		RemoteStopClockServiceInterface.getInstance().activityStarted(this);
	}


}